<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Welcome to my site</title>
<link rel="stylesheet" href="css/bootstrap.css"></link>
<link rel="stylesheet" href="css/bootstrap-theme.css"></link>
<link rel="stylesheet" href="css/font-awesome.min.css"></link>
<link rel="stylesheet" href="css/site.css"></link>
<style>

</style>
<script src="js/jquery3.3.1.min.js"></script> 
<script src="js/bootstrap.min.js"></script>   
<script src="js/json2.js"></script> 
<script src="js/md5.js"></script>
<script src="js/base.js"></script>    
</head>
<body>
<div id="app">
	<div class="loginbanner">   </div>
	<div class="loginpanel">
	<div class="panel panel-primary">
		<div class="panel-heading" style="height:45px">
					<h3 class="panel-title">登录</h3>
		</div>
        <div class="panel-body" >
		<form  id="loginForm" >

                <div class="col-xs-6 col-xs-offset-3 "><div class="input-group"><span class="input-group-addon"><i class="fa fa-user fa-fw" aria-hidden="true"></i></span><input class="form-control" id="username" name="username" placeholder="账号/手机/电子邮箱"></input></div></div>
                <br/><br/><br/>
                <div class="col-xs-6 col-xs-offset-3"><div id="passwordrow" class="input-group"><span class="input-group-addon"><i class="fa fa-key fa-fw" aria-hidden="true"></i></span><input class="form-control" type="password" placeholder="密 码"/><input type='hidden' id="password" name="password"/></div> </div>
               
				<div class="col-xs-6 col-xs-offset-3 "><div class="checkbox"><label></label></div>
				</div>
				
				<div class="col-xs-2 col-xs-offset-5 text-center"><input id="loginbtn" class="btn btn-primary" type="button" value="登录" ></div>

		</form>
		</div>
	</div>
	</div>
</div>
</body>
<script>
	
var login = function(data){
	$.ajax({
		url:URL_LOGIN,
		contentType:"charset=utf-8",
		data:data,
		dataType:"json",
		success:function(res,status,xhr){	
			sessionStorage.setItem("token",xhr.getResponseHeader("AUZ"));
			if(res.code=='200'){
				if(res.data){
					sessionStorage.setItem('sysfunc', JSON.stringify(res.data));
				}
				$(location).prop("href",getWebPath('HOME'));
				//如果需要保存账号
				if($("input[name='saveAccount']:checked").length>0){
					var expDate = new Date();
					expDate.setDate(expDate.getDate()+14);
					document.cookie='username='+$("#username").val()+';expires='+expDate.toGMTString();
				}
			}else if(res.msg){
						
				$("#passwordrow").after("<div class='alert alert-warning'><ul class='fa-ul'><li><i class='fa fa-exclamation-triangle fa-lg fa-li' aria-hidden='true'></i>"+res.msg+"</li></ul></div>");
			}else{
						
			}
		}
	});
}

$(document).ready(function(){
	//加载保存账号的cookie
	if(document.cookie.length>0){
		var c_start = document.cookie.indexOf("username=");
		if(c_start>=0){
			var x_end = document.cookie.indexOf(",",c_start+9);
			if(x_end == -1) x_end = document.cookie.length;
			$("#username").val(document.cookie.substring(c_start+9,x_end));
		}
	}
	
	$("#loginbtn").bind('click',function(){
		
		$(this).attr("disabled",true);
		$(".alert").remove();
		if($("#loginForm input[name='extcode']").length==0){
			$.ajax({
				url:URL_EXTCODE,
				contentType:"charset=utf-8",
				data:'t='+new Date(),
				dataType:"json",
				async:false,
				success:function(res){	
					if(res.extcode && res.salt){
						salt=res.extcode;
						$("#loginForm").append("<input type='hidden' name='extcode' value='"+res.salt+"'>").end();
					}
				}
			});
		}
		$("#password").val(md5(md5($(":password").val())+salt));
		login($("#loginForm").serialize());
		$(this).removeAttr("disabled");
	});
	
});

    </script>  
</html>
